package com.jd.oneday.month4;

/**
 * 有序合并数组问题
 * 要求如下：
 * 1. 时间复杂度O(m+n),不能是0「m*n」
 * 2. 不能调用sort函数
 */
public class Day_19 {


    public static void main(String[] args) {

        int[] array1 = {2,5,6,9};


        int[] array2 = {1,3,5,7,22};


        int max_current = 0;


        int new_length = array1.length + array2.length;


        // 创建新数组
        int[] result = new int[new_length];

        int x = 0;
        int y = 0;

        for (int i= 0;i<result.length;i++) {
            if (x== array1.length || array1[x] > array2[y]){
                max_current = array2[y];
                y++;
            } else{
                max_current = array1[x];
                x++;
            }
            result[i] = max_current;
        }

        System.out.println(result);


    }

}
